package com.mvc;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class ResponseUtil {
	
	// 没有登录
	public static void notLogin(HttpServletResponse response) throws IOException {
		response.setContentType("text/plain;charset=utf-8");
		response.getWriter().write("401 not authentication : 没有登录");
	}
	
	
	// 404
	public static void notFound(HttpServletResponse response) throws  IOException{
		response.setContentType("text/plain;charset=utf-8");
		response.getWriter().write("404 not found : 请求的路径不存在哦");
	}
	
	// 500
	public static void ServerError(HttpServletResponse resp) throws IOException {
		resp.setContentType("text/plain;charset=utf-8");
		resp.getWriter().write("500 内部错误");
	}
	
	// 500 ,json
	public static void ServerError(HttpServletResponse resp,String jsonMessage) throws IOException {
		resp.setContentType("text/json;charset=utf-8");
		resp.getWriter().write(jsonMessage);
	}
	
	
	// 500 ,json
	public static void ServerError2(HttpServletResponse resp,Object obj) throws IOException {
		resp.setContentType("text/json;charset=utf-8");
		resp.getWriter().write(JsonUtil.toJson(obj));
	}
}
